﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using FeiraGame_XNA.src.core.hud;
using FeiraGame_XNA.src.core;
namespace FeiraGame_XNA
{

    public static class Inputs
    {

        /// <summary>
        /// Static Variables
        /// </summary>
        #region Variables
        public static KeyboardState ckeyBoard, lkeyBoard;
        public static MouseState cMouse, lMouse;
        public static Rectangle cMouseBox;
        public static GamePadState cPad, lPad;
        private static Boolean controlState;
        #endregion

        /// <summary>
        /// Initialize
        /// </summary>
        #region Initialize
        public static void Initialize()
        {
            controlState = false;
            ckeyBoard = new KeyboardState();
            lkeyBoard = new KeyboardState();

            cMouse = new MouseState();
            lMouse = new MouseState();

            cPad = new GamePadState();
            lPad = new GamePadState();

            cMouseBox = new Rectangle(cMouse.X,cMouse.Y,1,1);
        }
        #endregion

        /// <summary>
        /// Update Function.
        /// </summary>
        #region Update
        public static void Update()
        {
           
            cMouse = Mouse.GetState();
            cMouseBox.X = cMouse.X;
            cMouseBox.Y = cMouse.Y;
            #region Update Inputs
            if (controlState)
            {
                cPad = lPad;
                ckeyBoard = lkeyBoard;
                controlState = false;
            }
            else
            {
                ckeyBoard = Keyboard.GetState();
                cPad = GamePad.GetState(PlayerIndex.One);
                controlState = true;
            }
          
            #endregion
            cMouse = lMouse;
        }
        #endregion

        /// <summary>
        /// Check if Keypress is down. Checa se tal Key está apertada SOMENTE UMA VEZ.
        /// </summary>
        /// <param name="keypress">How key you like check.  Key que você quer verificar</param>
        /// <returns>Return a bool</returns>
        #region CheckKey
        public static bool checkKey(Keys keypress)
        {
            if ((ckeyBoard.IsKeyDown(keypress)) && (!(lkeyBoard.IsKeyDown(keypress))))
                return true;
            return false;
        }
        #endregion

        /// <summary>
        /// Verifica Se uma tecla está CONSTANTEMENTE APERTADA.
        /// </summary>
        /// <param name="keypress">Key para ser verificada.</param>
        /// <returns>Verdadeiro ou Falso</returns>
        #region CheckKeyDown
        public static bool checkKeyDown(Keys keypress)
        {
            if (ckeyBoard.IsKeyDown(keypress))
                return true;
            return false;
        }
        #endregion

        /// <summary>
        /// Verifica se o mouse está clicando num botão
        /// </summary>
        /// <param name="target">Botão alvo para ser verificado.</param>
        /// <returns>Verdadeiro ou Falso.</returns>
        #region CheckClick
        public static bool checkClick(InterfaceObject target)
        {
            if ((cMouseBox.Intersects(target.ColisionBox) && ButtonState.Pressed == cMouse.LeftButton))
                return true;
            else
                return false;

        }
        #endregion

        /// <summary>
        /// Verifica se o mouse sob um objeto
        /// </summary>
        /// <param name="buttonCheck">objeto alvo para ser verificado.</param>
        /// <returns>Verdadeiro ou Falso.</returns>
        #region MouseOver
        public static bool MouseOver(InterfaceObject target)
        {
            if ((cMouseBox.Intersects(target.ColisionBox)))
                return true;
            else
                return false;

        }
        #endregion

        /// <summary>
        /// Verifica se o mouse está scrollando sob um determinado objeto
        /// </summary>
        /// <param name="target">Objeto de Interface</param>
        /// <returns></returns>
        #region isScrolling
        public static bool isScrolling(InterfaceObject target)
        {
            if (MouseOver(target) && ((cMouse.ScrollWheelValue < lMouse.ScrollWheelValue)))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        #endregion

    }

   
}
